package com.huaxin.device.mapping;

import com.huaxin.device.dto.enums.CircuitBreakerAction;
import com.huaxin.device.dto.request.CircuitBreakerScheduleCreateReqDTO;
import com.huaxin.device.dto.request.CircuitBreakerScheduleUpdateReqDTO;
import com.huaxin.device.models.CircuitBreakerSchedule;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface CircuitBreakerScheduleMapping {

    @Mapping(target = "action", ignore = true)
    CircuitBreakerSchedule toEntity(CircuitBreakerScheduleCreateReqDTO in);

    @AfterMapping
    default void afterMapping(CircuitBreakerScheduleCreateReqDTO in, @MappingTarget CircuitBreakerSchedule entity) {
        entity.setAction(CircuitBreakerAction.of(in.getAction()));
    }

    @Mapping(target = "action", ignore = true)
    void updateEntity(CircuitBreakerScheduleUpdateReqDTO in, @MappingTarget CircuitBreakerSchedule entity);

    @AfterMapping
    default void afterMapping(CircuitBreakerScheduleUpdateReqDTO in, @MappingTarget CircuitBreakerSchedule entity) {
        entity.setAction(CircuitBreakerAction.of(in.getAction()));
    }
}